#include "loopplaywidget.h"
#include "widgets/uloopplaywidget.h"
#include "widgets/unavigationbar.h"
#include "style/upalette.h"

#include <QVBoxLayout>
#include <QRandomGenerator>
#include <QAction>

const QVector<QString> textList =
{
    QObject::tr("Label"), QObject::tr("Button"), QObject::tr("LineEdit"), QObject::tr("datetime")
};

const QList<QString> iconList =
{
    "utk_label", "utk_button", "utk_lineedit", "utk_datetime",
    "utk_db", "utk_network", "utk_flag", "utk_lampbulb",
    "utk_message", "utk_notice", "utk_painter", "utk_settings",
    "utk_statistics", "utk_renew", "title"
};

LoopPalyWidget::LoopPalyWidget(QWidget* parent) : UWidget(parent)
{
    setBackgroundRole(QPalette::Base);
    setRadius(8);

    QVBoxLayout* layout = new QVBoxLayout;
    ULoopPalyWidget* loopPalyWidget = new ULoopPalyWidget(this);
    QList<QImage> imageList;
    for (int i = 0; i < 5; ++i)
    {
        imageList.append(QImage(QString(":/icons/card%1.jpeg").arg(i + 1)));
    }
    for (int i = 4; i >= 0; i--)
    {
        imageList.append(QImage(QString(":/icons/card%1.jpeg").arg(i + 1)));
    }
    loopPalyWidget->setImageList(imageList);
    loopPalyWidget->setFixedSize(800, 400);

    UNavigationBar* bar = new UNavigationBar(this);
    QAction action(QIcon::fromTheme("utkwidget"), QString());
    bar->setAction(action);
    bar->setRadius(0);
    bar->setFixedHeight(40);
    for (int i = 0; i < textList.size(); ++i)
    {
        bar->addButton(QIcon::fromTheme(iconList[i]), textList[i]);
    }
    connect(bar, &UNavigationBar::addButtonClicked, this, [bar, this] ()
    {
        int randomNumber = QRandomGenerator::global()->bounded(14);
        bar->addButton(QIcon::fromTheme(iconList[randomNumber]), QString("Random_%1").arg(randomNumber));
    });

    layout->addWidget(loopPalyWidget);
    layout->addWidget(bar);
    setLayout(layout);
}

LoopPalyWidget::~LoopPalyWidget()
{
}
